/**
 * 
 */
package com.scpii.universal.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.scpii.universal.hibernate.dao.PushMessageDao;
import com.scpii.universal.hibernate.entity.PushMessageTab;
import com.scpii.universal.service.PushMessageService;
import com.scpii.universal.util.SQLs;

/**
 * genericWeb
 * @author weny
 * 2012-7-8下午09:49:10
 */
@Service
public class PushMessageServiceImpl extends BaseServiceImpl<PushMessageTab, Integer> implements
		PushMessageService {
	@Resource
private PushMessageDao pushMessageDao;
	@Resource
	public void setBaseDao(PushMessageDao pushMessageDao) {
		super.setBaseDao(pushMessageDao);
	}
	/* (non-Javadoc)
	 * @see com.scpii.universal.service.PushMessageService#getMessageRecode(java.util.Map)
	 */
	 //消息展现记录数
	public static final String	TB_MESSAGELIST_COUNT="select COUNT(a.INT_PUSH_MSG_ID) from PUSH_MESSAGE_TAB a  WHERE a.INT_APP_ID=:intAppId and a.INT_DELETE_SIGN=0 ";
	
	@Override
	public Integer getMessageRecode(Map<String, Object> argsMap) {
		
		return pushMessageDao.getRecordNum(TB_MESSAGELIST_COUNT, argsMap);
	}
	/* (non-Javadoc)
	 * @see com.scpii.universal.service.PushMessageService#getMessageList(java.util.Map, int, int, int)
	 */
	/**demo
	 * 根据企业ID，页码，和每页显示数量，获得每页的显示记录
	 * @param pageStart 开始页码数
	 * @param pageRecordNo  结束页码数
	 * @param state（最新：0；往期：1）
	 * @return 
	 * @throws Exception  
	 */
	@Override
	public List<PushMessageTab> getMessageListPage(Map<String, Object> argsMap,
			int pageNo, int pageStart, int pageRecordNo) {
		// TODO Auto-generated method stub
		//设置最大的页码数
		int maxRowNum = pageRecordNo * pageNo;
		//设置最小的页码数
		int minRowNum = (pageNo - 1) * pageRecordNo;
		argsMap.put("MAXROWNUM", maxRowNum);
		argsMap.put("MINROWNUM", minRowNum);
		String whereString="";
		String querysql=SQLs.PUBLIC_STRS_HEAD+" (SELECT a.* FROM PUSH_MESSAGE_TAB a   WHERE a.INT_APP_ID=:intAppId and a.INT_DELETE_SIGN=0 "+
		whereString+"  ORDER BY int_Push_Msg_Id asc) "+SQLs.PUBLIC_STRS_BACK;
		return pushMessageDao.sqlGetList(querysql, argsMap);
	}
	/* (non-Javadoc)
	 * @see com.scpii.universal.service.PushMessageService#updateDeleteSign(java.lang.Integer)
	 */
	@Override
	public void updateDeleteSign(Integer msgId) {
		Map<String, Object> argsMap = new HashMap<String, Object>();
		argsMap.put("intPushMsgId", msgId);
		// TODO Auto-generated method stub
		String updateHql=" UPDATE Push_Message_Tab SET int_Delete_Sign=1 WHERE INT_PUSH_MSG_ID=:intPushMsgId";
		pushMessageDao.sqlUpdate(updateHql, argsMap);
	}
	
	
}
